﻿using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using PuzzleCollection.Games;
using PuzzleCollection.Games.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PuzzleCollection.Test.Games
{
    /// <summary>
    /// Unit tests of <see cref="NetGame"/>.
    /// </summary>
    [TestClass]
    public class NetGameTest
    {
        /// <summary>
        /// Test NetSettings serialization
        /// </summary>
        [TestMethod]
        public void NetGame_Settings()
        {
            var game = new NetGame();
            // Ensures that ParseSettings is correct
            foreach (var settings in game.PresetsSettings)
            {
                Assert.AreEqual(settings.Id, game.ParseSettings(settings.Id).Id);
            }
        }

        /// <summary>
        /// Check generatoion using a specific seed (results collected from reference c implementation)
        /// </summary>
        [TestMethod]
        public void NetGame_GenerateNewGameDescription()
        {
            var game = new NetGame();

            string aux;
            string result;

            //13x11#12300
            //13x11:6dc6ec83b42615466253e297c212656b1957825cc22be33a3dd6521ab6d74b31267d8a37a276de9bbe71ebad7255a24728b5ce3582bbdd186dd3565ea1b28285558196c65b21344
            result = game.GenerateNewGameDescription(new NetSettings(13, 11, false, true, 0.0f), OriginalRandom.FromTextSeed("12300"), out aux, 0);
            Assert.AreEqual("6dc6ec83b42615466253e297c212656b1957825cc22be33a3dd6521ab6d74b31267d8a37a276de9bbe71ebad7255a24728b5ce3582bbdd186dd3565ea1b28285558196c65b21344", result);

            //13x11#507896411361192
            //13x11:14c2a55e588c871c5984b2d6b2a238732b3ed686ab5d16de4c59895a721dd7e748ea377de612d42ee82e86d99b2657d5767cd2d618e5aeae1b9a53a317e5d3aaa242aa321824494
            result = game.GenerateNewGameDescription(new NetSettings(13, 11, false, true, 0.0f), OriginalRandom.FromTextSeed("507896411361192"), out aux, 0);
            Assert.AreEqual("14c2a55e588c871c5984b2d6b2a238732b3ed686ab5d16de4c59895a721dd7e748ea377de612d42ee82e86d99b2657d5767cd2d618e5aeae1b9a53a317e5d3aaa242aa321824494", result);

            //48x25#820543338195187
            //48x25:148432868c1d345b81897224342e81612417416a26188c883dd8d5cd8e59357b5de8d1a1bb4a1b75bd7b7b7327bb8acec4585bd2228ac33641b672517e1d8882157888d917838b1a75b7cd7bb4617ccdab97b2e7ed4a1ba6567e8433a72969d742b6498a613591b5e82658eb73694dc839a324dd7d815cd44b75618dd8983966745ee532e5d8db45a1758eb84c8e7c2147d3bb2ae96572adb4128381a9c4b21ee2a7dbda48ca65b639141bddaec86c1ceab849bda8aeda92b765c495adc7b42113444246167ea7312c13c92a67a915c3e815a4a56b4a8c3c8d9b59ae7b2368b5452cc6c95d7a1cddc237c942721b2ec617de3c8c183b65dcbea175ea6ce1c3e2366d77d7b777295d2adddeaaae38cc3e5b77ebb366aeea759378d88b45c5b55322558ca693e18c5e16ac2a27dec58eb75d4857941b73e5ecce9a846e31775a53932a318d5679ce83cdde9e7a2882e4a5445c63e711c72ce62a59d939d6e1a6d8814773caa774b15aa8adad984dde894ea55d139298c36cc5b487416559d3d14ab14b28c2de823196c55e5a55daebce7ce58696792a2a2c5ed5a3c6a24a5cb414337d5bbac372559b6a56ee6e4735421db695c57dc263eb914a814a7467b92a1b7a8189186c13788baa84e728e11964dd76869c23c5393b2aa8e7714881b95566aa165d68aa5881a3194d7a573e9a442a23b48ceb31d42cd824e94ce7b7bab91c57dc4cd3a82cdc37c5b41e97edebc2774dc22e79c8684ebabe3baea6bee46d127adbbea64718c14746852cd8a4e3ed86ed85175628a1db4cdd24cb2e4b77a21e15ebbc42dae5ac991922293549b8c82e4952271c141c5528
            result = game.GenerateNewGameDescription(new NetSettings(48, 25, false, true, 0.0f), OriginalRandom.FromTextSeed("820543338195187"), out aux, 0);
            Assert.AreEqual("148432868c1d345b81897224342e81612417416a26188c883dd8d5cd8e59357b5de8d1a1bb4a1b75bd7b7b7327bb8acec4585bd2228ac33641b672517e1d8882157888d917838b1a75b7cd7bb4617ccdab97b2e7ed4a1ba6567e8433a72969d742b6498a613591b5e82658eb73694dc839a324dd7d815cd44b75618dd8983966745ee532e5d8db45a1758eb84c8e7c2147d3bb2ae96572adb4128381a9c4b21ee2a7dbda48ca65b639141bddaec86c1ceab849bda8aeda92b765c495adc7b42113444246167ea7312c13c92a67a915c3e815a4a56b4a8c3c8d9b59ae7b2368b5452cc6c95d7a1cddc237c942721b2ec617de3c8c183b65dcbea175ea6ce1c3e2366d77d7b777295d2adddeaaae38cc3e5b77ebb366aeea759378d88b45c5b55322558ca693e18c5e16ac2a27dec58eb75d4857941b73e5ecce9a846e31775a53932a318d5679ce83cdde9e7a2882e4a5445c63e711c72ce62a59d939d6e1a6d8814773caa774b15aa8adad984dde894ea55d139298c36cc5b487416559d3d14ab14b28c2de823196c55e5a55daebce7ce58696792a2a2c5ed5a3c6a24a5cb414337d5bbac372559b6a56ee6e4735421db695c57dc263eb914a814a7467b92a1b7a8189186c13788baa84e728e11964dd76869c23c5393b2aa8e7714881b95566aa165d68aa5881a3194d7a573e9a442a23b48ceb31d42cd824e94ce7b7bab91c57dc4cd3a82cdc37c5b41e97edebc2774dc22e79c8684ebabe3baea6bee46d127adbbea64718c14746852cd8a4e3ed86ed85175628a1db4cdd24cb2e4b77a21e15ebbc42dae5ac991922293549b8c82e4952271c141c5528", result);

            //13x11w#12300
            //13x11w:5d55b98bb624c321c67a71c1594235c71243bb11a219b61e875a4ba7787abae512464bab1baa1c2799e6e49eb95d566a6b84bbcd5734149d1c5b7446b5d354ea9a4de288d3cb444
            result = game.GenerateNewGameDescription(new NetSettings(13, 11, true, true, 0.0f), OriginalRandom.FromTextSeed("12300"), out aux, 0);
            Assert.AreEqual("5d55b98bb624c321c67a71c1594235c71243bb11a219b61e875a4ba7787abae512464bab1baa1c2799e6e49eb95d566a6b84bbcd5734149d1c5b7446b5d354ea9a4de288d3cb444", result);

            //13x11w#507896411361192
            //13x11w:7d815d85d9531bb997ba2b845d8e6a28c8b4abd8725987eb83b82782546bd76c67ad69eebc131ce44a8d4ce4db2c4475d2d6ee12c2a61b4e19e43c345c71c58d8c958d97e488427
            result = game.GenerateNewGameDescription(new NetSettings(13, 11, true, true, 0.0f), OriginalRandom.FromTextSeed("507896411361192"), out aux, 0);
            Assert.AreEqual("7d815d85d9531bb997ba2b845d8e6a28c8b4abd8725987eb83b82782546bd76c67ad69eebc131ce44a8d4ce4db2c4475d2d6ee12c2a61b4e19e43c345c71c58d8c958d97e488427", result);

            //48x25w#820543338195187
            //48x25w:65a323b1297d415de557a6a992115667731ae3798ca388be662a7d72b3922464b4462113469814d41ddb7d95d789714db3e31877a9eb91d599828b979a165abe61746428ac55117d49761261871e143865865e4dabb21b919971e8627a5ba8914a21a2891baec6545a6757c772563588365cc3ead82ea862e36d7ecd31ad36ddde124e6358d4d71aa2ea2d89a49218ba882b18d1daac8aabd7b5de11a5a2e12be85bdbeb3152e7e26eae95ebe85e3277757346eca67aea62bec514c8155c923a6e69a53259e596c88887192a6e842ac9b14aaa8949ee5eebec849134a4486a1c3e26cc3c5d5b1c5b386d6d53aaee68a129adb518c359a2a2a584eabac9c8316869cd7be7abbc12e1599a3298162ed956dbd793d9695372e59ce4d22a3d8dd7dd825452edeaa75ebdc9561a2db73c6e775b44abc4e16b359da7554688c25b7acb4827642baceedb833d7b9ed684ba866d26dbdd941323a84e444cb6ccd3b459d2848b718eac4b629cd5d2a1dca75ed285335326c291363c95e4173a2e6c1658d548b8c6712aaeea72515ea5a5dadb9eb6b58be422686c82b37148cc642255a5dd7ed7ebe536b155973a1a86db6933d3d7ed74ba3de5baa5bc87aa15e167b62547b54c5d2aeb4165ec36c4612e293382b1cb2229463a369e8aeadc3db824c481419616c83d8e87c99bdbc9b55e9bc5239a417aa1e832b6da5ee615dbdd9e24731d28412cbc523688cd7358be919b96b9c542e613c2556b6216cde32e54ee75445a72b4a4c22ebb4521b288e31b9245abb34543abdbc8e7a66572a1c19694a41d4b6aa4418a1ac955c3a617e91a781d9a849211b99d7dba5e9a
            result = game.GenerateNewGameDescription(new NetSettings(48, 25, true, true, 0.0f), OriginalRandom.FromTextSeed("820543338195187"), out aux, 0);
            Assert.AreEqual("65a323b1297d415de557a6a992115667731ae3798ca388be662a7d72b3922464b4462113469814d41ddb7d95d789714db3e31877a9eb91d599828b979a165abe61746428ac55117d49761261871e143865865e4dabb21b919971e8627a5ba8914a21a2891baec6545a6757c772563588365cc3ead82ea862e36d7ecd31ad36ddde124e6358d4d71aa2ea2d89a49218ba882b18d1daac8aabd7b5de11a5a2e12be85bdbeb3152e7e26eae95ebe85e3277757346eca67aea62bec514c8155c923a6e69a53259e596c88887192a6e842ac9b14aaa8949ee5eebec849134a4486a1c3e26cc3c5d5b1c5b386d6d53aaee68a129adb518c359a2a2a584eabac9c8316869cd7be7abbc12e1599a3298162ed956dbd793d9695372e59ce4d22a3d8dd7dd825452edeaa75ebdc9561a2db73c6e775b44abc4e16b359da7554688c25b7acb4827642baceedb833d7b9ed684ba866d26dbdd941323a84e444cb6ccd3b459d2848b718eac4b629cd5d2a1dca75ed285335326c291363c95e4173a2e6c1658d548b8c6712aaeea72515ea5a5dadb9eb6b58be422686c82b37148cc642255a5dd7ed7ebe536b155973a1a86db6933d3d7ed74ba3de5baa5bc87aa15e167b62547b54c5d2aeb4165ec36c4612e293382b1cb2229463a369e8aeadc3db824c481419616c83d8e87c99bdbc9b55e9bc5239a417aa1e832b6da5ee615dbdd9e24731d28412cbc523688cd7358be919b96b9c542e613c2556b6216cde32e54ee75445a72b4a4c22ebb4521b288e31b9245abb34543abdbc8e7a66572a1c19694a41d4b6aa4418a1ac955c3a617e91a781d9a849211b99d7dba5e9a", result);
        }

    }
}
